#!/usr/bin/env python
# coding=utf-8
#
# commit msg check
import sys
import re
import io

if hasattr(sys.stdout, 'buffer'):
    sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')

TIPS_INFO = '''
不符合commit规范，提交失败（当前状态等于没做刚刚的commit操作）！

commit规范：
类型 详细消息

规范样例：
git commit -m "xxxxx xxxxxxxxxxxxx"

！！！！提交失败！！！！
'''

def check_commit_line1_format(msg):
    regOther = r'\S{5,} (.){10,100}'
    matchObj = re.match(regOther, msg)
    return matchObj

if __name__=="__main__":
    with open(sys.argv[1], 'r') as f:
        for line in f:
            if (check_commit_line1_format(line)):
                sys.exit(0)
            else:
                print(TIPS_INFO)
                sys.exit(1)